#
#   BasicKid.py
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 of the License.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   Copyright
#   Author: Nicholas F. Hoover
#   Contributors: 
#   Created: 2007.06.17
#   Last Modified: 2007.07.10
#

from GameObject import GameObject
from Enemy import Enemy
from Animation import Animation

class BasicKid(Enemy):
    NUM_ANIMATIONS = 6
    (RUN_UP,
     RUN_DOWN,
     RUN_SIDE,
     BITE,
     PUNCH,
     KICK) = range(NUM_ANIMATIONS)  
    
    LEFT = NUM_ANIMATIONS
      
    ###############
    # FPS FACTORS #
    ###############
    RUN_ANIMATION_FPS_FACTOR  = 6
    BITE_ANIMATION_FPS_FACTOR = 6

    ##############
    # KEY FRAMES #
    ##############
    BITE_KEY_FRAME = 1
      
    ###################
    # ANIMATION TABLE #
    ###################
    ANIMATION_TABLE = [ GameObject.BLANK_ANIMATION_ENTRY, #RUN_UP 
                        GameObject.BLANK_ANIMATION_ENTRY, #RUN_DOWN
                        (RUN_SIDE, 'BasicKid_Run_Right',  RUN_ANIMATION_FPS_FACTOR,  Animation.NO_KEY_FRAME),
                        (BITE,     'BasicKid_Bite_Right', BITE_ANIMATION_FPS_FACTOR, BITE_KEY_FRAME),
                        GameObject.BLANK_ANIMATION_ENTRY, #PUNCH
                        GameObject.BLANK_ANIMATION_ENTRY, #KICK
                        GameObject.BLANK_ANIMATION_ENTRY, #RUN_UP + LEFT
                        GameObject.BLANK_ANIMATION_ENTRY, #RUN_DOWN + LEFT
                        (RUN_SIDE + LEFT, 'BasicKid_Run_Left',  RUN_ANIMATION_FPS_FACTOR,  Animation.NO_KEY_FRAME),
                        (BITE     + LEFT, 'BasicKid_Bite_Left', BITE_ANIMATION_FPS_FACTOR, BITE_KEY_FRAME),
                        GameObject.BLANK_ANIMATION_ENTRY, #PUNCH + LEFT
                        GameObject.BLANK_ANIMATION_ENTRY, #KICK + LEFT
                        ]
    
    #############
    # MOVEMENTS #
    #############
    MOVEMENTS = [ (0,-2),   #RUN_UP
                  (0,2),    #RUN_DOWN
                  (2,0),    #RUN_SIDE
                  (0,0),    #BITE
                  (0,0),    #PUNCH
                  (0,0)]    #KICK

    DEFAULT_ANIMATION = RUN_SIDE
 
##########
# SOUNDS #
##########   
    NUM_SOUNDS = NUM_ANIMATIONS

    ###############
    # SOUND TABLE #
    ###############    
    SOUND_TABLE = [GameObject.BLANK_SOUND_ENTRY, #RUN_UP
                   GameObject.BLANK_SOUND_ENTRY, #RUN_DOWN
                   GameObject.BLANK_SOUND_ENTRY, #RUN_SIDE
                   (BITE, 'Kid_Bite'),
                   GameObject.BLANK_SOUND_ENTRY, #PUNCH
                   GameObject.BLANK_SOUND_ENTRY] #KICK
    
 
###########
# ATTACKS #    
###########   
    BITE_DAMAGE = 5
    

########
# MISC #
########
    DEFAULT_POSITION = (0,0)
    RECT_SIZE = (30,50)

#############
# FUNCTIONS #
#############
    def __init__(self):
        Enemy.__init__(self)
        self.update = self.update1

    def update1(self, evilGregRect):
        hitEvilGreg = self.moveTowardTarget(evilGregRect)
                
        if hitEvilGreg:
            self.currentAnimation = BasicKid.BITE + self.facing
        else:
            self.currentAnimation = BasicKid.RUN_SIDE + self.facing
            
        self.animations[self.currentAnimation].update()
        self.updateCurrentImage()
        #HACK
        movement = self.MOVEMENTS[self.currentAnimation - self.facing]
        if self.currentAnimation == BasicKid.RUN_SIDE + BasicKid.LEFT:
            movement = (-movement[0], movement[1])
        self.rect.left += movement[0]
        self.rect.top += movement[1]


    #Why is this variation of the function so buggy
    def update2(self, evilGregRect):
        if self.animations[self.currentAnimation].update():
            hitEvilGreg = self.moveTowardTarget(evilGregRect)
        
            if hitEvilGreg:
                self.currentAnimation = BasicKid.BITE + self.facing


            self.updateCurrentImage()
            #HACK
            movement = self.MOVEMENTS[self.currentAnimation - self.facing]
            if self.currentAnimation == BasicKid.RUN_SIDE + BasicKid.LEFT:
                movement = (-movement[0], movement[1])
            self.rect.left += movement[0]
            self.rect.top += movement[1]
